/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package yuhuibear.poat.test.entity;

import java.util.Date;
import java.util.Random;

import yuhuibear.poat.annotations.action.AutoGenerateValue;
import yuhuibear.poat.annotations.action.Macro;
import yuhuibear.poat.annotations.relation.Field;
import yuhuibear.poat.annotations.relation.Table;
import yuhuibear.poat.object.bean.Bean;

/**
 * 
 * @author yuhuibear
 */

@Table(name = "log222s", constrain = "")
public class Log implements Bean {

	/**
	 * 
	 */
	private static final long serialVersionUID = 131633989874564920L;
	@AutoGenerateValue(skipOnNull = true, sqlToGet = "select currval('log222s_id_seq')")
	@Field(name = "id", type = "bigserial", constrain = " primary key")
	private Long id;
	@Field(name = "name", type = "varchar(40)", constrain = "")
	private String name;
	@Field(name = "dsp", type = "varchar(255)", constrain = "")
	private String dsp;

	@Field(name = "date", type = "date", constrain = "")
	private Date date;

	@Field(name = "time", type = "timestamp", constrain = "")
	private Date time;

	@Field(name = "value", type = "int", constrain = "")
	private int value;
	
	@Field(name = "longvalue", type = "int8", constrain = "")
	private long longvalue;

	@Macro(name = "d1", depend = "")
	public String createD1() {
		return "drop table if exists d1; create table d1(id serial primary key, fid int)";
	}

	@Macro(name = "r2", depend = "")
	public String createR2() {
		return "CREATE OR REPLACE FUNCTION r2(i integer) RETURNS integer AS $$ "
				+ "BEGIN  RETURN i + 1; END;" + "$$ LANGUAGE plpgsql;";
	}

	@Field(name = "owner_id", type = "int8 ", constrain = "references users(id)")
	private Long ownerId;

	public Log() {
	}

	public Log(String name) {
		Random rand = new Random();
		this.name = name + rand.nextLong();
		dsp = null; // "dsp " + rand.nextLong();
		// ownerId = rand.nextInt(29) + 1;

	}

	public Long getId() {
		return id;
	}

	/**
	 * 
	 * @param id
	 */
	public void setId(Long id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getDsp() {
		return dsp;
	}

	public void setDsp(String dsp) {
		this.dsp = dsp;
	}

	public Date getTime() {
		return time;
	}

	public void setTime(Date time) {
		this.time = time;
	}

	@Override
	public String toString() {
		return id + ", " + name + ", " + ", " + dsp + ", " + time
				+ ", ownerId : " + this.ownerId;
	}

	public Date getDate() {
		return date;
	}

	public void setDate(Date date) {
		this.date = date;
	}

	public int getValue() {
		return value;
	}

	public void setValue(int value) {
		this.value = value;
	}

	public Long getOwnerId() {
		return ownerId;
	}

	public void setOwnerId(Long ownerId) {
		this.ownerId = ownerId;
	}

	public long getLongvalue() {
		return longvalue;
	}

	public void setLongvalue(long longvalue) {
		this.longvalue = longvalue;
	}

}
